home *** CD-ROM | disk | FTP | other *** search
- Path: news1.h1.usa.pipeline.com!usenet
- From: grantp@usa.pipeline.com(Pete)
- Newsgroups: comp.lang.c++
- Subject: Re: Increasing stack size - HELP!
- Date: 25 Feb 1996 10:50:21 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4gpetd$qu2@news1.usa.pipeline.com>
- References: <NEWTNews.825237165.25683.koz@dialup.netvision.net.il>
- NNTP-Posting-Host: pipe14.h1.usa.pipeline.com
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete)
- X-Newsreader: Pipeline USA v3.3.0
-
- On Feb 25, 1996 00:23:09 in article <Re: Increasing stack size - HELP!>,
- 'koz@netvision.net.il' wrote:
-
- >> From: Francesco Fantauzzi <mapgfgf@brunel.ac.uk>
- >> Newsgroups: comp.lang.c++,comp.lang.c
- >> Subject: Increasing stack size - HELP!
- >> Date: 20 Feb 1996 11:58:09 GMT
- >>
- >> Hi All!
- >>
- >> I'm using Borland C++ 4.0. I'm stuck 'cause, when I run my program, it
- >> stops with a run-time error: "STACK OVERFLOW!".
- >>
- >> I checked the stack size (with stackavail()) and it's actually too
- small.
- >> How can I tell the compiler that I would like a larger stack, overriding
-
- >> the default size? I'm sure there's a way: I did it years ago, but have
- >> forgotten it.
- >>
- >> BTW, I'm writing a plain MS-DOS application with the compact memory
- >> model.
- >>
- >> Thanks for any help.
- >>
- >> Francesco G. Fantauzzi
- >>
- >>
- >Just use the next line :
- >
- >extern unsigned _stklen = NewStackSize;
- >
- >(It should be writen in the global section of the program, not in
- >ANY procedure).
- > ..[ portions trimmed ]
-
- Although the above may work in some cases, and occasionally may
- even be the best solution, generally it's not a good idea. Running
- out of stack space is often caused by poor programming practices,
- usually by those with little experience in software development.
-
- To the original poster, I'd like to suggest that you examine your
- program to see where you are using up the stack unnecessarily
- and use allocation off the global heap instead. Examples of
- such "fixups" are:
-
- int Boo ()
- {
- int foo[500];
-
- Here you are grabbing off 1000 or 2000 bytes off the stack,
- depending on the size of int on your machine. Either move
- the declaration outside the function into global space (not my
- recommendation), or better yet, use dynamic memory:
-
- int Boo ()
- {
- int * foo = new int[500];
-
- (Your post was to both comp.lang.c and c++. If you're a
- C programmer, use malloc instead of new).
-
- If the poster's only interest is in getting the current program to
- run so that it can earn its writer a grade, then I've wasted my
- time -- and bandwith -- :-)
-
- --
- Pete Grant
- Kalevi, Inc.
- Software Engineering & development
-